<?php
/**
 * This file is part of the Yacms (http://www.yacms.org)
 * Copyright (c) 2019 gylr0505 (http://www.yacms.org)
 *
 * Author: 鬼一浪人 <gylr0505@163.com>
 *
 * DateTime: 19-10-24 下午8:41
 * Description:
 */
 
declare(strict_types = 1);

namespace App\Template\Queue;

use App\Model\Entity\Template;

class Manager
{
    /**
     * @var \ArrayObject
     */
    protected $objects;

    /**
     * Manager constructor
     */
    public function __construct()
    {
        $this->objects = new \ArrayObject();
    }

    /**
     * @param null $app_id
     * @param string $type
     * @throws \Swoft\Db\Exception\DbException
     */
    public function scan($app_id = null, $type = '*')
    {
        $list = Template::query()->where([
            'app_id' => $app_id
        ])->get()->toArray();

        if (!$list){
            return;
        }

        foreach ($list as $item){
            if ($item['type'] != $type && $type != '*'){
                continue;
            }
            $this->objects->append($item);
        }

        $list = null;
    }
}